import java.sql.*;

public class Login
{
	public static String username = null;
	public static String password = null;
	public static String role = null;
	public static String error = null;
	public static int userid = 0;
	public static boolean login_status = false;

	public Login(String user, String pass) throws SQLException
	{
		username = user;
		Connector conn = new Connector("select * from user where username = '" + username + "'");
		ResultSet rs = conn.execute();
		if(rs.first())
		{
			password = rs.getString("password");
			role = rs.getString("role");
			userid = rs.getInt("userid");

			if(password.equals(pass))
				login_status = true;
			else
				error = "Login faild. Password wrong.";
		}
		else
		{
			error = "Login faild. User not exist.";
		}
		rs.close();		
	}

	public static String getRole()
	{
		if(login_status != false)
		{
			return role;
		}
		else
			return null;
	}

	public static boolean getLoginStatus()
	{
		return login_status;
	}

	public static String getError()
	{
		return error;
	}

	public static int getUserId()
	{
		return userid;
	}
}
